#include <cstdio>
#include <algorithm>
const int max=8;
int N;
int flag[max] = {0};
int seq[max] = {0};
int count=0;
int print(int n)
{
    int i,j;
    if (n == N)
    {
        ++count;
        for (i = 0; i < N; ++i)
            for (j = i + 1; j < N; ++j)
            {
                if (std::abs(i-j)==std::abs(seq[i]-seq[j]))
                {
                    --count;
                    return 0;
                }
            }
        return 0;
    }
    for (j = 0; j < N; ++j)
    {
        if (0 == flag[j])
        {
            seq[n] = j + 1;
            flag[j] = 1;
            print(n + 1);//每次递归调用都递进一层
            flag[j] = 0;
        }
    }
}
int main()
{
    scanf("%d", &N);
    print(0);
    printf("count=%d\n",count);
}